package com.petadoption.serverclient.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.petadoption.serverclient.entity.Address;
import com.petadoption.serverclient.mapper.AddressMapper;
import com.petadoption.serverclient.service.IAddressService;
import com.petadoption.serverclient.vo.AddressVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements IAddressService {

    @Resource
    private AddressMapper addressMapper;

    @Override
    public List<AddressVO> findAddressAll(Integer userId) {
        return addressMapper.findAddressAll(userId);
    }

    @Override
    public int addAddress(AddressVO addressVO) {

        return addressMapper.addAddress(addressVO);
//        return addressMapper.insert(address);
    }

    @Override
    public int updateAddress(Address address) {
        return addressMapper.update(address, new UpdateWrapper<Address>().eq("address_id", address.getAddressId()));
    }

    @Override
    public Address findAddress(Integer addressId, Integer userId) {
        return addressMapper.selectOne(new QueryWrapper<Address>().eq("address_id", addressId).eq("address_uid", userId));
    }

    @Override
    public int deleteAddress(Integer addressId, Integer userId) {
        return addressMapper.delete(new UpdateWrapper<Address>().eq("address_id", addressId).eq("address_uid", userId));
    }
}
